package model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedList;

import view.AddressListView;

public class AddressList extends LinkedList<Address> implements Serializable,
		ISubject {
	private static final long serialVersionUID = -8436170099085318899L;

	private ArrayList<IViews> registredAddresListViews = new ArrayList<IViews>();

	@Override
	public void registrieren(AddressListView addressListView) {
		registredAddresListViews.add(addressListView);

	}

	@Override
	public void addNewAdress(Address address) {
		this.add(address);
		benachrichtigeAllSubscribers();

	}

	@Override
	public void unregistrieren(AddressListView addressListView) {
		int addressListViewIndex = this.registredAddresListViews
				.indexOf(addressListView);
		this.registredAddresListViews.remove(addressListViewIndex);

	}

	@Override
	public void benachrichtigeAllSubscribers() {
		for (int i = 0; i < registredAddresListViews.size(); i++) {
			registredAddresListViews.get(i).update();
		}

	}

}
